package com.iflytek.day18;

import java.util.Objects;

class Student2 {
  String name;
  int age;

  public Student2(String name, int age) {
    this.name = name;
    this.age = age;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    this.age = age;
  }

  @Override
  public String toString() {
    System.out.println(getClass().getName() + "@" + Integer.toHexString(hashCode()));
    return "Student2{" +
            "name='" + name + '\'' +
            ", age=" + age +
            '}';
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Student2 student2 = (Student2) o;
    return age == student2.age && Objects.equals(name, student2.name);
  }

  @Override
  public int hashCode() {
    return 0;
  }
}

public class _12_ObjectDemo {
  public static void main(String[] args) {

    // 创建两个学生对象
    Student2 s1 = new Student2("iflytek", 14);
    Student2 s2 = new Student2("iflytek", 14);

    // 比较两个对象是否相等
    System.out.println(s1 == s2); // false
    System.out.println(s1.equals(s2)); // false

  }
}
